﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="~/MainSys/Manager/Controls/ctAddNewArticle.ascx.cs" Inherits="KhoaLuan.MainSys.Manager.Controls.ctAddNewArticle" %>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

<script src="/Scripts/AjaxUpload.js"></script>
<script src="/Scripts/dluscript.js"></script>
<style>
    .treenode {
        list-style: none;
        margin-left: 10px;
        padding-left: 10px;
    }

    .node {
        cursor: pointer;
        font-size: 18px;
    }
</style>

<script>
    $(document).ready(function () {
        $("#fileHinhMinhHoa").change(function () {
            readURL(this);
        });

        $('.typearticle').change(function () {
            debugger;
            if ($('#<%=typeTinTuc.ClientID%>')[0].checked)
                $('#<%=cbChuyenMuc.ClientID%>').removeAttr('disabled');
            else
                $('#<%=cbChuyenMuc.ClientID%>').attr('disabled', 'disabled');
        });

        function GetQueryString(name) {
            var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.href);
            return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
        }

        $('#<%=btnDangBai.ClientID%>').click(function () {
            if ($('#<%=typeTinTuc.ClientID%>')[0].checked) {
                if ($('#<%=cbChuyenMuc.ClientID%>').val() == "") {
                    alert("Vui lòng chọn chuyên mục cho bài viết")
                    return;
                }
            }
            debugger;
            var path = $("#fileHinhMinhHoa").val();
            if (path == "") {
                Save(null);
            }
            else {
                UploadAjax($("#fileHinhMinhHoa"), "/ProcessAJAX/UploadFileAJAX.ashx", function (response) {
                    debugger;
                    var obj = JSON.parse(response);
                    if (obj.Status) {
                        Save(obj.Location);
                    };
                })
            }
        });

        function Save(image) {
            debugger;
            var orgid = GetQueryString("OrgID");
            var articleid = GetQueryString("ArticleID");
            CallAjaxAspx("POST", "DangBai", "/MainSys/ProcessAJAX/AjaxArticle.aspx",
                            {
                                idbaiviet: articleid != null ? articleid : 0,
                                orgid: orgid != null ? orgid : 1,
                                tieude: $("#<%=txtTieuDe.ClientID%>").val(),
                                theloai: parseInt($("input[class=typearticle]:checked").val()),
                                chuyenmuc: $("#<%=cbChuyenMuc.ClientID%>").val(),
                                hinhminhhoa: image,
                                noidungvantat: CKEDITOR.instances['<%=txtVanTat.ClientID%>'].getData(),
                                noidungdaydu: CKEDITOR.instances['<%=txtNoiDung.ClientID%>'].getData()
                            }, function (response) {
                                debugger;
                                var obj = JSON.parse(response);
                                if (obj.Status) {
                                    alertSmallBox("Lưu bài viết thành công", "2 giây trước", "success");
                                    window.history.back();
                                }
                                else {
                                    alertbox("Lưu bài viết không thành công");
                                }
                            }, AjaxLoading(true), AjaxLoading(false));

        }

        function readURL(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();

                reader.onload = function (e) {
                    $('#<%=imgHinhMinhHoa.ClientID%>').attr('src', e.target.result);
                }

                reader.readAsDataURL(input.files[0]);
                }
            }
    });


</script>



<section id="widget-grid" class="">
    <div class="row">
        <article class="col-sm-12 col-md-12 col-lg-12">
            <div class="alert alert-info alert-block">
                <h4 class="alert-heading" style="font-weight: bold">VIẾT BÀI VIẾT CHO :
                    <label runat="server" id="lbOrg" style="font-weight: bold">sdf</label>
                </h4>
            </div>
            <div class="jarviswidget">
                <header>
                    <span class="widget-icon"><i class="fa fa-edit"></i></span>
                    <h2>Soạn thảo nội dung </h2>
                </header>
                <div>
                    <!-- widget content -->
                    <div class="widget-body no-padding">
                        <div class="smart-form">
                            <header>
                                Tiêu đề bài viết
                            </header>

                            <fieldset>
                                <div class="row">
                                    <section style="padding: 0 10px;">
                                        <label class="input">
                                            <i class="icon-append fa fa-edit"></i>
                                            <input type="text" id="txtTieuDe" runat="server">
                                            <b class="tooltip tooltip-bottom-right">Bạn cần nhập tiêu đề bài viết</b>
                                        </label>
                                    </section>
                                </div>
                            </fieldset>
                            <header>
                                Thể loại
                            </header>

                            <fieldset>
                                <div class="row">
                                    <section style="padding: 0 10px; margin-top: -10px !important;">
                                        <div class="inline-group" style="float: left; margin-right: 10px;">
                                            <label class="radio">
                                                <input type="radio" value="1" name="rdKieu" checked="true" class="typearticle" id="typeTinTuc" runat="server">
                                                <i></i>Tin tức</label>
                                        </div>
                                        <div class="inline-group" style="float: left">
                                            <label class="radio">
                                                <input type="radio" value="2" name="rdKieu" class="typearticle" id="typeThongBao" runat="server">
                                                <i></i>Thông báo</label>
                                        </div>
                                    </section>
                                </div>
                            </fieldset>
                            <header>
                                Thể loại
                            </header>

                            <fieldset>
                                <div class="row">
                                    <section style="padding: 0 10px;">
                                        <div class="form-group">
                                            <asp:DropDownList runat="server" ID="cbChuyenMuc" CssClass="select2" Style="width: 100%">
                                            </asp:DropDownList>
                                        </div>
                                    </section>
                                </div>
                            </fieldset>
                            <header>
                                Hình minh họa
                            </header>

                            <fieldset>
                                <div class="row">
                                    <section style="padding: 0 10px;">
                                        <div class="form-group">
                                            <div style="float: left; width: 100px; height: 100px; border: 1px dashed rgba(0,0,0,.2)">
                                                <asp:Image runat="server" ID="imgHinhMinhHoa" Style="width: 100px; height: 100px;" />
                                            </div>
                                            <div style="margin-left: 120px;">
                                                <div>
                                                    <input type="file" class="btn btn-default" id="fileHinhMinhHoa">
                                                </div>
                                            </div>
                                        </div>
                                    </section>
                                </div>
                            </fieldset>
                            <header>
                                Nội dung vắn tăt
                            </header>

                            <fieldset>
                                <div class="row">
                                    <section style="padding: 0 10px;">
                                        <CKEditor:CKEditorControl ID="txtVanTat" runat="server" Height="100">
                                        </CKEditor:CKEditorControl>
                                    </section>
                                </div>
                            </fieldset>
                            <header>
                                Nội dung đầy đủ
                            </header>
                            <fieldset>
                                <div class="row">
                                    <section style="padding: 0 10px;">
                                        <CKEditor:CKEditorControl ID="txtNoiDung" runat="server" Height="300">
                                        </CKEditor:CKEditorControl>
                                    </section>
                                </div>
                            </fieldset>
                            <footer>
                                <input type="button" id="btnDangBai" class="btn btn-primary" value="Đăng bài" runat="server">
                                <input type="button" class="btn btn-default" value="Hủy" onclick="window.history.back();">
                            </footer>
                        </div>
                    </div>
                </div>
            </div>
        </article>
    </div>
</section>


